﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject;
using VietTrips.Domain.Interfaces;
using VietTrips.Domain.Repositories;

namespace VietTrips.WebUI.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private readonly IKernel _ninjectKernel;

        public NinjectControllerFactory()
        {
            _ninjectKernel = new StandardKernel();
            AddBinding();
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return controllerType == null
                ? null
                : (IController) _ninjectKernel.Get(controllerType);
        }

        private void AddBinding()
        {
            _ninjectKernel.Bind<ITourAgencyRepository>().To<TourAgencyRepository>();
            _ninjectKernel.Bind<IUserRepository>().To<UserRepository>();
        }
    }
}